package com.example.goods_service.dao;

import com.example.goods_service.vo.*;
import org.apache.ibatis.annotations.*;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface GoodsDao_chenbin {
    @Select(" select * from  t_commodity_category where category_parent_ID = 0")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "name",column = "category_name"),
            @Result(property = "category_parent_ID",column = "category_parent_ID")
    })
    List<T_commodity_category> sel_big_leimu();

    @Select(" select * from  t_commodity_category where category_parent_ID <> 0")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "name",column = "category_name"),
            @Result(property = "category_parent_ID",column = "category_parent_ID")
    })
    List<T_commodity_category> sel_small_leimu();

    @Select("  select * from t_category_attribute where category_id = #{category_id} ")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "category_id",column = "category_id"),
            @Result(property = "attribute",column = "attribute")
    })
    List<T_category_attribute> sel_attribute(int category_id);

    @Select("  select * from t_attribute_details  ")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "attribute_id",column = "attribute_id"),
            @Result(property = "details",column = "details")
    })
    List<T_attribute_details> sel_details();

    @Select(" select * from t_category_config where category_id = #{category_id} ")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "category_id",column = "category_id"),
            @Result(property = "configuration_type",column = "configuration_type"),
    })
    List<T_category_config> sel_goodsconfig(int category_id);

    @Select("select * from t_config_details ")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "config_id",column = "config_id"),
            @Result(property = "config_details",column = "config_details")
    })
    List<T_config_details> sel_configdetails();

    @Insert("insert into t_picture(picture_path_name) VALUES(#{s})")
    int add_picture(String s);

    @Insert("insert into t_commodity(commodity_name,commodity_description, status,sales_volume,release_time,category_id) value(#{goodsname},#{goodsjianjie},'1',0,now(), #{leimuid})")
    int addgoods(String goodsname, String goodsjianjie, int leimuid);

    @Select("select id from t_commodity where commodity_name = #{goodsname} ")
    @Result(property = "id",column = "id")
    List<T_commodity> sel_goodsid(String goodsname);

    @Insert("insert into t_selected_attribute(attribute_id,attribute_details_id,goods_id) values(#{attribute_id},#{attribute_details_id},#{goodsid})")
    void add_selectedattribute(int attribute_id, int attribute_details_id, int goodsid);

    @Select("select * from t_config_details where config_details = #{o} ")
    List<T_config_details> sel_configdetailsid(String o);

    @Insert("insert into t_selected_config(config_id,config_details_id,goods_id) values(#{config_id},#{id},#{id1})")
    int add_selected_config(int id, int config_id, int id1);

    @Insert("insert into t_commodity_allocation(commodity_id,attribute,price,stock,update_time) values(#{id},#{configattibute},#{goodsrice},#{stock},now() ) ")
    int add_com_all(int id, String configattibute, Double goodsrice, int stock);

    @Update("UPDATE t_commodity set commodity_picture = #{s} where id = #{id} ")
    void add_good_pic(String s, int id);

    @Update("UPDATE t_commodity set commodity_price = #{pirce} where id = #{id} ")
    void add_com_pic(@Param("pirce") Double pirce, @Param("id") int id);

    @Select("select COUNT(1) from t_commodity a,t_dianpu_goods b where a.id= b.goodsid and  b.userid =  #{userid} ")
    int sel_goodstotal(int userid);

    @Select("select id  from t_picture where picture_path_name = #{s} ")
    @Results({
            @Result(property = "id",column = "id")
    })
    List<T_picture> sel_picid(String s);

    @Insert("insert into t_commodity_picture(commodity_id,picture_id) values(#{id},#{id1})")
    void add_goodspic(int id, int id1);

    @Insert("insert into t_category_attribute(category_id,attribute) values(#{categoryid},#{attribute})")
    int add_attribute(@Param("categoryid") int categoryid, @Param("attribute")String attribute);

    @Insert("insert into t_attribute_details(attribute_id,details) values(#{attributeid},#{attibutedetails}) ")
    int add_attributedetails(@Param("attributeid")int attributeid, @Param("attibutedetails")String attibutedetails);

    @Select("select * from t_category_attribute where attribute = #{attribute} and category_id = #{categoryid} ")
    List<T_category_attribute> sel_attribute_exsit(@Param("attribute")String attribute,@Param("categoryid")int categoryid);

    @Select("select * from t_category_config where configuration_type = #{configname} and category_id  = #{categoryid} ")
    List<T_category_config> sel_config_exsit(@Param("configname")String configname,@Param("categoryid")int categoryid);

    @Insert("insert into t_config_details(config_id,config_details) values(#{configid},#{configdetails}) ")
    int add_config_details(@Param("configid")int configid, @Param("configdetails")String configdetails);

    @Insert("insert into t_category_config(category_id,configuration_type) values(#{categoryid},#{configname}) ")
    int add_config(@Param("categoryid")int categoryid, @Param("configname")String configname);

    @Insert("insert into t_dianpu_goods(userid,goodsid) values(#{userid},#{id}) ")
    void add_dianpu_goods(@Param("userid") int userid, @Param("id") int id);

    @Select("select COUNT(1) from t_commodity a,t_dianpu_goods b where a.id= b.goodsid and  b.userid = #{userid} and a.status = '1' ")
    int sel_shangjianum(int userid);

    @Select("select COUNT(1) from t_commodity a,t_dianpu_goods b where a.id= b.goodsid and  b.userid = #{userid} and a.status = '2' ")
    int sel_xiajia(int userid);
}
